import pygame
import math

class StandardView(object):
    def __init__(self,imageFolder,window, squareSize,cursorColor):
        s=cursorColor.split(",")
        self._cursorColor=(int(s[0]),int(s[1]),int(s[2]))
        self._imageFolder=imageFolder
        self._squareSize=int(squareSize)
        self._images=self.loadImages()
        pygame.init()
        self._window = window.window();
        self._gameWindow = window
        self._screenHeight = window.height();
        self._screenWidth = window.width();
        self._currentTLRow = 0
        self._currentTLCol = 0
    
    @property
    def imageFolder(self):
        return self._imageFolder

    @imageFolder.setter
    def imageFolder(self, value):
        self._imageFolder = value
        
    def loadImage(self,name):
        return(pygame.image.load(self._imageFolder+'\\'+name))
        
    def loadImages(self):
        images={}
        images['pipes']={}
        images['pipes']['n']={}
        images['pipes']['n']['regular']=self.loadImage('Industrial pipes2.png')
        images['tree']={}
        images['tree']['n']={}
        images['tree']['n']['regular']=self.loadImage('Impassible tree.png')
        images['sand']={}
        images['sand']['n']={}
        images['sand']['n']['regular']=self.loadImage('Sandbags.png')
        images['color0']=self.loadImage('color0.png')
        images['swamp']={}
        images['swamp']['n']={}
        images['swamp']['n']['regular']=self.loadImage('swamp.bmp')
        images['castle']={}
        images['castle']['n']={}
        images['castle']['n']['regular']=self.loadImage('castle.bmp')
        images['farm']={}
        images['farm']['n']={}
        images['farm']['n']['regular']=self.loadImage('farm.bmp')
        images['mine']={}
        images['mine']['n']={}
        images['mine']['n']['regular']=self.loadImage('mine.bmp')
        images['indock']={}
        images['indock']['n']={}
        images['indock']['n']['regular']=self.loadImage('Dock.png')
        images['color1']=self.loadImage('color1.png')
        images['color2']=self.loadImage('color2.png')
        images['color3']=self.loadImage('color3.png')
        images['number0']=self.loadImage('number0.png')
        images['number1']=self.loadImage('number1.png')
        images['number2']=self.loadImage('number2.png')
        images['number3']=self.loadImage('number3.png')
        images['number4']=self.loadImage('number4.png')
        images['number5']=self.loadImage('number5.png')
        images['number6']=self.loadImage('number6.png')
        images['number7']=self.loadImage('number7.png')
        images['number8']=self.loadImage('number8.png')
        images['number9']=self.loadImage('number9.png')
        images['blankWhite']=self.loadImage('blankWhite.png')
        images['targetedSquare']=self.loadImage('targetedSquare.png')
        images['targetedSquareLight']=self.loadImage('targetedSquareLight.png')
        images['newSurfaceObj']=self.loadImage('unknown.gif')
        images['menuHorizontal']=self.loadImage('menuSideHorizontal.png')
        images['menuVertical']=self.loadImage('menuSideVertical.png')
        images['menuBL']=self.loadImage('menuBL.png')
        images['menuBR']=self.loadImage('menuBR.png')
        images['menuTL']=self.loadImage('menuTL.png')
        images['menuTR']=self.loadImage('menuTR.png')
        images['blank']=self.loadImage('blankwhite.png')
        images['selected']=self.draw_cursor()#self.loadImage('selected.gif')
        images['forest']={}
        images['forest']['n']={}
        images['road']={}
        images['road']['n']={}
        images['mountain']={}
        images['mountain']['n']={}
        images['water']={}
        images['water']['n']={}
        images['plain']={}
        images['plain']['n']={}
        images['shoal']={}
        images['shoal']['n']={}
        images['HQ']={}
        images['HQ']['0']={}
        images['HQ']['1']={}
        images['HQ']['2']={}
        images['HQ']['3']={}
        images['city']={}
        images['city']['n']={}
        images['city']['0']={}
        images['city']['1']={}
        images['city']['2']={}
        images['city']['3']={}
        images['reef']={}
        images['reef']['n']={}
        images['airport']={}
        images['airport']['n']={}
        images['airport']['0']={}
        images['airport']['1']={}
        images['airport']['2']={}
        images['airport']['3']={}
        images['base']={}
        images['base']['n']={}
        images['base']['0']={}
        images['base']['1']={}
        images['base']['2']={}
        images['base']['3']={}
        images['port']={}
        images['port']['n']={}
        images['port']['0']={}
        images['port']['1']={}
        images['port']['2']={}
        images['port']['3']={}
        images['indu']={}
        images['indu']['n']={}
        images['indu']['n']['regular']=self.loadImage('Industrial ground.png')
        images['pipe']={}
        images['pipe']['n']={}
        images['pipe']['n']['regular']=self.loadImage('Industrial pipes.png')
        images['forest']['n']['regular']=self.loadImage('forest.bmp')
        images['road']['n']['regular']=self.loadImage('road.bmp')
        images['mountain']['n']['regular']=self.loadImage('mountain.bmp')
        images['water']['n']['regular']=self.loadImage('water.bmp')
        images['plain']['n']['regular']=self.loadImage('plain.bmp')
        images['HQ']['0']['regular']=self.loadImage('HQ0.bmp')
        images['HQ']['0']['highlight']=self.loadImage('HQ0_highlight.bmp')
        images['HQ']['1']['regular']=self.loadImage('HQ1.bmp')
        images['HQ']['1']['highlight']=self.loadImage('HQ1_highlight.bmp')
        images['HQ']['2']['regular']=self.loadImage('HQ2.bmp')
        images['HQ']['2']['highlight']=self.loadImage('HQ2_highlight.bmp')
        images['HQ']['3']['regular']=self.loadImage('HQ3.bmp')
        images['HQ']['3']['highlight']=self.loadImage('HQ3_highlight.bmp')
        images['city']['n']['regular']=self.loadImage('cityn.bmp')
        images['city']['n']['highlight']=self.loadImage('cityn_highlight.bmp')
        images['city']['0']['regular']=self.loadImage('city0.bmp')
        images['city']['0']['highlight']=self.loadImage('city0_highlight.bmp')
        images['city']['1']['regular']=self.loadImage('city1.bmp')
        images['city']['1']['highlight']=self.loadImage('city1_highlight.bmp')
        images['city']['2']['regular']=self.loadImage('city2.bmp')
        images['city']['2']['highlight']=self.loadImage('city2_highlight.bmp')
        images['city']['3']['regular']=self.loadImage('city3.bmp')
        images['city']['3']['highlight']=self.loadImage('city3_highlight.bmp')
        images['reef']['n']['regular']=self.loadImage('reef.bmp')
        images['crate']={}
        images['crate']['n']={}
        images['crate']['n']['regular']=self.loadImage('airportn.bmp')
        images['airport']['n']['regular']=self.loadImage('airportn.bmp')
        images['airport']['n']['highlight']=self.loadImage('airportn_highlight.bmp')
        images['airport']['0']['regular']=self.loadImage('airport0.bmp')
        images['airport']['0']['highlight']=self.loadImage('airport0_highlight.bmp')
        images['airport']['1']['regular']=self.loadImage('airport1.bmp')
        images['airport']['1']['highlight']=self.loadImage('airport1_highlight.bmp')
        images['airport']['2']['regular']=self.loadImage('airport2.bmp')
        images['airport']['2']['highlight']=self.loadImage('airport2_highlight.bmp')
        images['airport']['3']['regular']=self.loadImage('airport3.bmp')
        images['airport']['3']['highlight']=self.loadImage('airport3_highlight.bmp')
        images['base']['n']['regular']=self.loadImage('basen.bmp')
        images['base']['n']['highlight']=self.loadImage('basen_highlight.bmp')
        images['base']['0']['regular']=self.loadImage('base0.bmp')
        images['base']['0']['highlight']=self.loadImage('base0_highlight.bmp')
        images['base']['1']['regular']=self.loadImage('base1.bmp')
        images['base']['1']['highlight']=self.loadImage('base1_highlight.bmp')
        images['base']['2']['regular']=self.loadImage('base2.bmp')
        images['base']['2']['highlight']=self.loadImage('base2_highlight.bmp')
        images['base']['3']['regular']=self.loadImage('base3.bmp')
        images['base']['3']['highlight']=self.loadImage('base3_highlight.bmp')
        images['port']['n']['regular']=self.loadImage('portn.bmp')
        images['port']['n']['highlight']=self.loadImage('portn_highlight.bmp')
        images['port']['0']['regular']=self.loadImage('port0.bmp')
        images['port']['0']['highlight']=self.loadImage('port0_highlight.bmp')
        images['port']['1']['regular']=self.loadImage('port1.bmp')
        images['port']['1']['highlight']=self.loadImage('port1_highlight.bmp')
        images['port']['2']['regular']=self.loadImage('port2.bmp')
        images['port']['2']['highlight']=self.loadImage('port2_highlight.bmp')
        images['port']['3']['regular']=self.loadImage('port3.bmp')
        images['port']['3']['highlight']=self.loadImage('port3_highlight.bmp')
        images['shoal']['n']['regular']=self.loadImage('shoal.bmp')
        images['forest']['n']['highlight']=self.loadImage('forest_highlight.bmp')
        images['road']['n']['highlight']=self.loadImage('road_highlight.bmp')
        images['mountain']['n']['highlight']=self.loadImage('mountain_highlight.bmp')
        images['water']['n']['highlight']=self.loadImage('water_highlight.bmp')
        images['plain']['n']['highlight']=self.loadImage('plain_highlight.bmp')
        images['reef']['n']['highlight']=self.loadImage('reef_highlight.bmp')
        images['shoal']['n']['highlight']=self.loadImage('shoal_highlight.bmp')
        images['infantry']={}
        images['boat']={}
        images['boat'][2]={}
        images['boat'][2]['moved']=self.loadImage('infantry2.png')
        images['boat'][2]['unmoved']=self.loadImage('infantry2moved.png')
        images['infantry'][0]={}
        images['infantry'][0]['unmoved']=self.loadImage('infantry0.png')
        images['infantry'][0]['moved']=self.loadImage('infantry0moved.png')
        images['infantry'][1]={}
        images['infantry'][1]['unmoved']=self.loadImage('infantry1.png')
        images['infantry'][1]['moved']=self.loadImage('infantry1moved.png')
        images['infantry'][2]={}
        images['infantry'][2]['unmoved']=self.loadImage('infantry2.png')
        images['infantry'][2]['moved']=self.loadImage('infantry2moved.png')
        images['infantry'][3]={}
        images['infantry'][3]['unmoved']=self.loadImage('infantry3.png')
        images['infantry'][3]['moved']=self.loadImage('infantry3moved.png')
        images['submarine']={}
        images['submarine'][0]={}
        images['submarine'][0]['unmoved']=self.loadImage('submarine0.png')
        images['submarine'][0]['moved']=self.loadImage('submarine0moved.png')
        images['submarine'][1]={}
        images['submarine'][1]['unmoved']=self.loadImage('submarine1.png')
        images['submarine'][1]['moved']=self.loadImage('submarine1moved.png')
        images['submarine'][2]={}
        images['submarine'][2]['unmoved']=self.loadImage('submarine2.png')
        images['submarine'][2]['moved']=self.loadImage('submarine2moved.png')
        images['submarine'][3]={}
        images['submarine'][3]['unmoved']=self.loadImage('submarine3.png')
        images['submarine'][3]['moved']=self.loadImage('submarine3moved.png')
        images['helicopter']={}
        images['helicopter'][0]={}
        images['helicopter'][0]['unmoved']=self.loadImage('helicopter0.png')
        images['helicopter'][0]['moved']=self.loadImage('helicopter0moved.png')
        images['helicopter'][1]={}
        images['helicopter'][1]['unmoved']=self.loadImage('helicopter1.png')
        images['helicopter'][1]['moved']=self.loadImage('helicopter1moved.png')
        images['helicopter'][2]={}
        images['helicopter'][2]['unmoved']=self.loadImage('helicopter2.png')
        images['helicopter'][2]['moved']=self.loadImage('helicopter2moved.png')
        images['helicopter'][3]={}
        images['helicopter'][3]['unmoved']=self.loadImage('helicopter3.png')
        images['helicopter'][3]['moved']=self.loadImage('helicopter3moved.png')
        images['blimp']={}
        images['blimp'][0]={}
        images['blimp'][0]['unmoved']=self.loadImage('blimp0.png')
        images['blimp'][0]['moved']=self.loadImage('blimp0moved.png')
        images['blimp'][1]={}
        images['blimp'][1]['unmoved']=self.loadImage('blimp1.png')
        images['blimp'][1]['moved']=self.loadImage('blimp1moved.png')
        images['blimp'][2]={}
        images['blimp'][2]['unmoved']=self.loadImage('blimp2.png')
        images['blimp'][2]['moved']=self.loadImage('blimp2moved.png')
        images['blimp'][3]={}
        images['blimp'][3]['unmoved']=self.loadImage('blimp3.png')
        images['blimp'][3]['moved']=self.loadImage('blimp3moved.png')
        images['randy']={}
        images['randy'][0]={}
        images['randy'][0]['unmoved']=self.loadImage('randy.png')
        images['randy'][0]['moved']=self.loadImage('randy1.png')
        images['dan']={}
        images['dan'][0]={}
        images['dan'][0]['moved']=self.loadImage('dan.png')
        images['dan'][0]['unmoved']=self.loadImage('dan1.png')
        images['savage']={}
        images['savage'][1]={}
        images['savage'][1]['moved']=self.loadImage('savage.png')
        images['savage'][1]['unmoved']=self.loadImage('savage1.png')
        images['bomb']={}
        images['bomb'][1]={}
        images['bomb'][1]['moved']=self.loadImage('bomb.png')
        images['bomb'][1]['unmoved']=self.loadImage('bomb.png')
        images['chicken']={}
        images['chicken'][1]={}
        images['chicken'][1]['moved']=self.loadImage('chicken.png')
        images['chicken'][1]['unmoved']=self.loadImage('chicken.png')
        images['mech']={}
        images['mech'][0]={}
        images['mech'][0]['unmoved']=self.loadImage('mech0.png')
        images['mech'][0]['moved']=self.loadImage('mech0moved.png')
        images['mech'][1]={}
        images['mech'][1]['unmoved']=self.loadImage('mech1.png')
        images['mech'][1]['moved']=self.loadImage('mech1moved.png')
        images['mech'][2]={}
        images['mech'][2]['unmoved']=self.loadImage('mech2.png')
        images['mech'][2]['moved']=self.loadImage('mech2moved.png')
        images['mech'][3]={}
        images['mech'][3]['unmoved']=self.loadImage('mech3.png')
        images['mech'][3]['moved']=self.loadImage('mech3moved.png')
        images['diggs']={}
        images['diggs'][0]={}
        images['diggs'][0]['moved']=self.loadImage('diggs.png')
        images['diggs'][0]['unmoved']=self.loadImage('diggs.png')
        images['diggs'][2]={}
        images['diggs'][2]['moved']=self.loadImage('diggs.png')
        images['diggs'][2]['unmoved']=self.loadImage('diggs.png')
        for key in images.keys():
            if type(images[key]) is dict:
                for k in images[key].keys():
                    if 'regular' in images[key][k].keys():
                        orig = images[key][k]['regular'].copy()
                        alpha = pygame.Surface((orig.get_width(),orig.get_height()))
                        alpha.set_alpha(150)
                        alpha.fill((0,0,75))
                        alpha.convert()
                        orig.blit(alpha,(0,0))
                        images[key][k]['highlight']=orig
        return(images)
    def draw_cursor(self):
        cursor_width = 3
        size = self._squareSize
        line_length = round(self._squareSize*.33)
        cursor_color = (self._cursorColor[0],self._cursorColor[1],self._cursorColor[2],255)
        surf = pygame.Surface((size,size),flags=pygame.SRCALPHA)
        surf.set_alpha(0)
        size = size-int(cursor_width/2)
        pygame.draw.lines(surf,cursor_color,False,[(0,line_length),(0,0),(line_length,0)],cursor_width)#top-left
        pygame.draw.lines(surf,cursor_color,False,[(0,size-line_length),(0,size),(line_length,size)],cursor_width)#bottom-left
        pygame.draw.lines(surf,cursor_color,False,[(size-line_length,size),(size,size),(size,size-line_length)],cursor_width)#bottom-right
        pygame.draw.lines(surf,cursor_color,False,[(size-line_length,0),(size,0),(size,line_length)],cursor_width)#top-right
#        pygame.draw.rect(surf,cursor_color,pygame.Rect(0,0,size-1,size-1),2)
        return surf.convert_alpha()
        
    def makeMenuItem(self,text,selected,font,width):
        t = font.render(text, 1, (0,0,0))
        text = pygame.Surface((width,font.get_linesize()))
        if selected:
            text.fill((155,155,155))
        else:
            text.fill((255,255,255))
        textPos = t.get_rect()
        textPos.centerx = text.get_rect().centerx
        textPos[1]=0
        text.blit(t,textPos)
        text.convert()
        return text
    
    def drawMenu(self,subject):
        font = pygame.font.Font(None, 24)
        menuWidth = font.size(max("Move","End","Attack","Capture","Cancel",key=lambda s: font.size(s)[0]))[0]
        menuItemHeight = font.get_linesize()
        menuItemCount=len(list(filter(None,subject.validMenuButtons)))
        menuFullWidth=menuWidth+4
        menuFullHeight=menuItemCount*menuItemHeight+4
        menu=pygame.Surface((menuFullWidth, menuFullHeight))
        menuBrdr=pygame.Surface((menuWidth+2, menuItemCount*menuItemHeight+2))
        menuBg = pygame.Surface((menuWidth, menuItemCount*menuItemHeight))
        menu.fill((255,255,255))
        menuBrdr.fill((0,0,0))
        menu.blit(menuBrdr,(1,1))
        menuBg.fill((255,255,255))
        pos=0
        
        moveMenuItem=self.makeMenuItem("Move",subject.currentMenuButton==0,font,menuWidth)
        attkMenuItem=self.makeMenuItem("Attack",subject.currentMenuButton==1,font,menuWidth)
        capMenuItem=self.makeMenuItem("Capture",subject.currentMenuButton==2,font,menuWidth)
        endMenuItem=self.makeMenuItem("End",subject.currentMenuButton==3,font,menuWidth)
        cancelMenuItem=self.makeMenuItem("Cancel",subject.currentMenuButton==4,font,menuWidth)
        
        if subject.validMenuButtons[0]:
            textpos = moveMenuItem.get_rect()
            textpos.centerx = menuBg.get_rect().centerx
            textpos[1]=pos*menuItemHeight
            menuBg.blit(moveMenuItem,textpos)
            pos += 1
        if subject.validMenuButtons[1]:
            textpos = attkMenuItem.get_rect()
            textpos.centerx = menuBg.get_rect().centerx
            textpos[1]=pos*menuItemHeight
            menuBg.blit(attkMenuItem,textpos)
            pos += 1
        if subject.validMenuButtons[2]:
            textpos = capMenuItem.get_rect()
            textpos.centerx = menuBg.get_rect().centerx
            textpos[1]=pos*menuItemHeight
            menuBg.blit(capMenuItem,textpos)
            pos += 1
        if subject.validMenuButtons[3]:
            textpos = endMenuItem.get_rect()
            textpos.centerx = menuBg.get_rect().centerx
            textpos[1]=pos*menuItemHeight
            menuBg.blit(endMenuItem,textpos)
            pos += 1
        textpos = cancelMenuItem.get_rect()
        textpos.centerx = menuBg.get_rect().centerx
        textpos[1]=pos*menuItemHeight
        menuBg.blit(cancelMenuItem,textpos)
        menu.blit(menuBg,(2,2))
        selectedXpos = subject._selectedSquare[1]*self._squareSize
        selectedYpos = subject._selectedSquare[0]*self._squareSize
        maxX = min(self._screenWidth,subject.grid.getColumns()*self._squareSize)
        maxY = min(self._screenHeight,subject.grid.getRows()*self._squareSize)
        menuYpos = selectedYpos
        menuXpos = selectedXpos
        if maxY<selectedYpos+menuFullHeight:
            menuYpos=maxY-menuFullHeight
        if maxX<selectedXpos+menuFullWidth:
            menuXpos=maxX-menuFullWidth    
        self._window.blit(menu,(menuXpos,menuYpos))
    def genHealthBar(self,health,team):
        size = self._squareSize
        bar_thickness = 5
        bar_width=round(size*.8)
        colors={0:(40,100,5,255),1:(255,0,0,255),2:(150,150,150,0),3:(150,150,150,0)}
        bar_color=colors[team]
        base_color=(150,150,150,255)
        surf=pygame.Surface((size,size),flags=pygame.SRCALPHA)
        surf2=pygame.Surface((bar_width,size),flags=pygame.SRCALPHA)
        surf.set_alpha(0)
        surf2.set_alpha(0)
        start=(0,size-bar_thickness)
        end_full=(bar_width,size-bar_thickness)
        endscaledx= 0.5*bar_width if (health<10) else bar_width#(math.ceil(size*(health/10.0)),5)
        end_scaled=(endscaledx,size-bar_thickness)
        pygame.draw.line(surf2,base_color,start,end_full,bar_thickness)
        pygame.draw.line(surf2,bar_color,start,end_scaled,bar_thickness)
        pos = surf2.get_rect()
        pos.centerx = surf.get_rect().centerx
        pos[1]=0
        surf.blit(surf2,pos)
        return surf.convert_alpha()
    def update(self,subject):
        self._window.fill(pygame.Color(255,255,255))
        if(subject._won==True):
            pass;
        else:
            selectedRowPos = subject._selectedSquare[0]
            selectedColumnPos = subject._selectedSquare[1]
            gameplayScreenMaxWidth = self._screenWidth
            gameplayScreenMaxHeight = self._screenHeight
            gameplayNumberOfRowsInView = int(gameplayScreenMaxHeight / self._squareSize)
            gameplayNumberOfColsInView = int(gameplayScreenMaxWidth / self._squareSize)
            if(selectedRowPos < (self._currentTLRow+2)):
                self._currentTLRow = max((selectedRowPos - 2),0)
            elif((self._currentTLRow + gameplayNumberOfRowsInView - 1) < selectedRowPos):
                self._currentTLRow = min((selectedRowPos - gameplayNumberOfRowsInView + 2),(subject.grid.getRows() - gameplayNumberOfRowsInView))
            if(selectedColumnPos < (self._currentTLCol+2)):
                self._currentTLCol = max((selectedColumnPos - 2),0)
            elif((self._currentTLCol + gameplayNumberOfColsInView - 2) < selectedColumnPos):
                self._currentTLCol = min((selectedColumnPos - gameplayNumberOfColsInView + 2),(subject.grid.getColumns() - gameplayNumberOfColsInView))
            
            for row in range(self._currentTLRow,min(self._currentTLRow+gameplayNumberOfRowsInView,subject.grid.getRows())):
                for column in range(self._currentTLCol,min(self._currentTLCol+gameplayNumberOfColsInView ,subject.grid.getColumns())):
                    cell=subject.grid.getCell(row,column)
                    rowPos=(row - self._currentTLRow)*self._squareSize
                    columnPos=(column - self._currentTLCol)*self._squareSize
                    if(True):
                        imageType=str(cell.getlType())
                        imageSecondary=str(cell.getSecondary())
                        imageTeam=cell.getFaction()
                        if(imageTeam==None):
                            imageTeam='n'
                        else:
                            imageTeam=str(imageTeam)
                        image=self._images[imageType][imageTeam][imageSecondary]
                            
                        image=pygame.transform.scale(image,(self._squareSize,self._squareSize))
                        self._window.blit(image,(columnPos,rowPos))
                        if(subject.focus=='menu'):
                            if(subject.currentMenuButton==1):
                                if((row,column) in subject._targetedUnits):
                                    targetImage=pygame.transform.scale(self._images['targetedSquareLight'],(self._squareSize,self._squareSize))
                                    self._window.blit(targetImage,(columnPos,rowPos))
                        if(subject.focus=='fire'):
                            if((row,column) in subject._targetedUnits):
                                if((row,column)==subject._targetedUnits[subject._currentTarget]):
                                    targetImage=pygame.transform.scale(self._images['targetedSquare'],(self._squareSize,self._squareSize))
                                else:
                                    targetImage=pygame.transform.scale(self._images['targetedSquareLight'],(self._squareSize,self._squareSize))
                                self._window.blit(targetImage,(columnPos,rowPos))
                        if(cell.getUnit()!=None):
                            unit=cell.getUnit()
                            unitType=unit.getType()
                            unitTeam=unit.getTeam()
                            unitState=unit.getState()
                            unitImage=self._images[unitType][unitTeam][unitState]
                            unitImage=pygame.transform.scale(unitImage,(self._squareSize,self._squareSize))
                            self._window.blit(unitImage,(columnPos,rowPos))
                            self._window.blit(self.genHealthBar(unit.getHealth(),unitTeam),(columnPos,rowPos))
                            #unitHealth=math.ceil(unit.getHealth())
#                            if(unitHealth!=10):
#                                unitHealthText=''.join(['number',str(int(unitHealth))])
#                                print(unitHealthText)
#                                subSquareSize=int(self._squareSize/1.75)
#                                unitHealthImage=pygame.transform.scale(self._images[unitHealthText],(subSquareSize,subSquareSize))
#                                self._window.blit(unitHealthImage,((columnPos+self._squareSize-subSquareSize,rowPos+self._squareSize-subSquareSize)))
#            rightPanel = pygame.Surface((200,self._screenHeight))
#            rightPanel.fill(pygame.Color(255,255,255))
#            self._window.blit(rightPanel, (gameplayScreenMaxWidth,0))
            selected2=pygame.transform.scale(self._images['selected'],(self._squareSize,self._squareSize))
            self._window.blit(selected2,((selectedColumnPos - self._currentTLCol)*self._squareSize,(selectedRowPos- self._currentTLRow)*self._squareSize))
#            fontThing2=pygame.font.Font('freesansbold.ttf',10)
#            playerText=str(subject._players[subject._turnOrder[subject._currentTurn]].getName())
#            playerTextObj = fontThing2.render(playerText, False, pygame.Color(0,0,0))
#            self._window.blit(playerTextObj,(self._screenWidth-60,10))
#            playerMoney=str(subject._players[subject._turnOrder[subject._currentTurn]].getMoney())
#            playerMoneyObj = fontThing2.render(playerMoney, False, pygame.Color(0,0,0))
#            self._window.blit(playerMoneyObj,(self._screenWidth-60,25))
            #Land popup
            if(subject.focus=='fire'):
#                subjectThing=subject._targetedUnits[subject._currentTarget]
#                subjectRow=subjectThing[0]
#                subjectCol=subjectThing[1]
                selectedCell=subject._grid.getCell(subject._targetedUnits[subject._currentTarget][0],subject._targetedUnits[subject._currentTarget][1])
            else:
                selectedCell=subject._grid.getCell(subject._selectedSquare[0],subject._selectedSquare[1])
            selectedImageType=str(selectedCell.getlType())
            selectedImageTeam=selectedCell.getFaction()
            if(selectedImageTeam==None):
                selectedImageTeam='n'
            else:
                selectedImageTeam=str(selectedImageTeam)
#            image=self._images[selectedImageType][selectedImageTeam]['regular']
#            image=pygame.transform.scale(image,(40,40))
#            self._window.blit(image,(self._screenWidth-80,65))
#            landText="Land: "+str(selectedCell.getlType())
#            landTextObj = pygame.font.Font('freesansbold.ttf',10).render(landText, False, pygame.Color(0,0,0))
#            self._window.blit(landTextObj,(self._screenWidth-80,115))
#            capCostText="Cap: "+str(selectedCell.getCaptureCost())
#            capCostTextObj = pygame.font.Font('freesansbold.ttf',10).render(capCostText, False, pygame.Color(0,0,0))
#            self._window.blit(capCostTextObj,(self._screenWidth-80,135))
            selectedUnit=selectedCell.getUnit()
            if(selectedUnit!=None):
                selectedUnitType=selectedUnit.getType()
                selectedUnitTeam=selectedUnit.getTeam()
                selectedUnitImage=self._images[selectedUnitType][selectedUnitTeam]['unmoved']
                selectedUnitImage=pygame.transform.scale(selectedUnitImage,(40,40))
#                self._window.blit(selectedUnitImage,(self._screenWidth-180,65))
                healthText="Health: "+str(math.ceil(selectedUnit.getHealth()))
                healthTextObj = pygame.font.Font('freesansbold.ttf',10).render(healthText, False, pygame.Color(0,0,0))
#                self._window.blit(healthTextObj,(self._screenWidth-180,115))
                height = 135
                for weapon in selectedUnit.getInventory():
                    weaponText=str(weapon.getWeaponClass()+ "-" +str(weapon.getName()))
                    weaponTextObj=pygame.font.Font('freesansbold.ttf',10).render(weaponText, False, pygame.Color(0,0,0))
#                    self._window.blit(weaponTextObj,(self._screenWidth-190,height))
                    weaponAmmo="Ammo: " + str(weapon.getCurrentAmmo())+"/"+str(weapon.getMaxAmmo())
                    weaponAmmoObj=pygame.font.Font('freesansbold.ttf',10).render(weaponAmmo, False, pygame.Color(0,0,0))
#                    self._window.blit(weaponAmmoObj,(self._screenWidth-175,height+15))
                    weaponStrEvade = "Str: "+ str(weapon.getStrength()) + "  Evade:" + str(weapon.getWeaponEvasion())
                    weaponStrEvadeObj = pygame.font.Font('freesansbold.ttf',10).render(weaponStrEvade, False, pygame.Color(0,0,0))
#                    self._window.blit(weaponStrEvadeObj,(self._screenWidth-175,height+30))
                    weaponHitCrit = "Hit: " + str(weapon.getWeaponCritChance()) + "%  Crit:" + str(weapon.getWeaponHitChance()) + "%"
                    weaponHitCritObj = pygame.font.Font('freesansbold.ttf',10).render(weaponHitCrit, False, pygame.Color(0,0,0))
#                    self._window.blit(weaponHitCritObj,(self._screenWidth-175,height+45))
                    height = height + 60
            currentColorName=''.join(['color',str(subject._turnOrder[subject._currentTurn])])
            currentColor=pygame.transform.scale(self._images[currentColorName],(50,50))
#            self._window.blit(currentColor,(self._screenWidth-200,0))
            currentTeamNumber = self._images["number"+str(subject._turnOrder[subject._currentTurn])]
            currentTeamNumber = pygame.transform.scale(currentTeamNumber,(50,50))
#            self._window.blit(currentTeamNumber, (self._screenWidth-150,0))
#            if(subject.focus=='creation'):
#                creationSqSize=20
#                creationStartingHeight = 200
#                currentRow=0
#                fontThing=pygame.font.Font('freesansbold.ttf',10)
#                for unit,cost in  subject.creationPlaces[subject._grid.getCell(subject._selectedSquare[0],subject._selectedSquare[1]).getlType()].items():
#                    if(currentRow==subject._currentCreation):
#                        fontThing.set_bold(True)
#                    else:
#                        fontThing.set_bold(False)
#                    unitText=str(unit+':'+cost)
#                    if(int(cost)<=subject._players[subject._turnOrder[subject._currentTurn]].getMoney()):
#                        unitTextObj = fontThing.render(unitText, False, pygame.Color(0,0,0))
#                    else:
#                        unitTextObj = fontThing.render(unitText, False, pygame.Color(200,200,200))
#                    self._window.blit(unitTextObj,(610,creationStartingHeight+ (creationSqSize*(currentRow))))
#                    currentRow=currentRow+1
            #show menu
            if(subject.focus=='menu'):
                self.drawMenu(subject)
        if subject.getDisplayText():
            self._gameWindow.displayText(subject.getDisplayText())
        pygame.display.update()
